home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
Xprof
/
xprof
/
gc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
14KB
|
457 lines
/*==================================================================
* File : gc.c
* Package: Xprof
*
* Author : Aloke Gupta.
*
* (C) Copyright 1992, Aloke Gupta.
*==================================================================*/
/*
* XprofGCvalues *create_gcval(int gcid)
* XprofGCvalues *get_gcval(int gcid)
* free_gcval(int gcid)
* copy_gcval(long src_id, long dst_id, int gcmask)$/
* fill_gcmask(char *ptr, int *gcmask)
* fill_gcval (FILE *fp, int valmask, XprofGCvalues *gcval)
* gc_gfxindex (FILE *fp, int req_num, XprofGCvalues *gcval)
* gc_fontindex(FILE *fp, int req_num, XprofGCvalues *gcval)
* FontVal *create_fontval(long fontid)
* FontVal *get_fontval(long fontid)
* free_fontval(long fontid)
*/
#include <stdio.h>
#include "common.h"
#include "profile.h"
char* db_font_name();
XprofGCvalues *create_gcval();
XprofGCvalues *get_gcval();
FontVal *create_fontval();
FontVal *get_fontval();
extern MsgType RequestType[]; /* Defined in table.c */
static AttributesTable GxmodeTable[]={
/*
* index , xprof_name, xscope_name, where, value
*/
GXCLEAR, "GXclear", "Clear", GXCOPY, -1,
GXAND, "GXand", "And", GXXOR, -1,
GXANDREVERSE, "GXandReverse", "AndReverse", GXXOR, -1,
GXCOPY, "GXcopy", "Copy", GXCOPY, 0, /* <-- */
GXANDINVERTED, "GXandInverted","AndInverted", GXXOR, -1,
GXNOOP, "GXnoop", "Noop", GXCOPY, -1,
GXXOR, "GXxor", "Xor", GXXOR, 1, /* <-- */
GXOR, "GXor", "Or", GXOR, -1,
GXNOR, "GXnor", "Nor", GXXOR, -1,
GXEQUIV, "GXequiv", "Equiv", GXXOR, -1,
GXINVERT, "GXinvert", "Invert", GXCOPY, -1,
GXORREVERSE, "GXorReverse", "OrReverse", GXXOR, -1,
GXCOPYINVERTED,"GXcopyInverted","CopyInverted",GXCOPY, -1,
GXORINVERTED, "GXorInverted", "OrInverted", GXXOR, -1,
GXNAND, "GXnand", "Nand", GXXOR, -1,
GXSET, "GXset", "Set", GXCOPY, -1,
};/* GxmodeTable */
unsigned int MAXGXMODES = sizeof(GxmodeTable) / sizeof(AttributesTable);
static AttributesTable LineStyleTable[] = {
/*
* index , xprof_name, xscope_name, where, value
*/
LINESOLID, "LineSolid", "Solid", LINESOLID, 0,/* <-- */
LINEONOFFDASH, "LineOnOffDash", "OnOffDash", LINEDOUBLEDASH, -1,
LINEDOUBLEDASH, "LineDoubleDash", "DoubleDash", LINEDOUBLEDASH, 1,/* <-- */
}; /*LineStyleTable */
unsigned int MAXLINESTYLES = sizeof(LineStyleTable) / sizeof(AttributesTable);
static AttributesTable FillStyleTable[] = {
/*
* index , xprof_name, xscope_name, where, value
*/
FILLSOLID, "FillSolid", "Solid", FILLSOLID, 0,
FILLOPAQUESTIPPLED,"FillOpaqueStippled","OpaqueStippled",FILLOPAQUESTIPPLED,1,
FILLSTIPPLED, "FillStippled", "Stippled", FILLOPAQUESTIPPLED,-1,
FILLTILED, "FillTiled", "Tiled", FILLOPAQUESTIPPLED,-1,
}; /* FillStyleTable */
unsigned int MAXFILLSTYLES = sizeof(FillStyleTable) / sizeof(AttributesTable);
/* GC maintenance routines */
static XprofGCvalues *gclist_head = NULL;
XprofGCvalues *create_gcval(gcid)
long gcid;
{
XprofGCvalues *gcval, *gcptr;
/* Allocate a gcval with all elements zero */
gcval = (XprofGCvalues *) calloc(1, sizeof(XprofGCvalues));
if (gclist_head == NULL) /* Empty list ? Insert at the head */
gclist_head = gcval;
else { /* Attach it at the end of the list */
gcptr = gclist_head;
while(gcptr->next != NULL)
gcptr = gcptr->next;
gcptr->next = gcval;
gcval->next = NULL;
}
gcval->id = gcid;
return gcval;
}
XprofGCvalues *get_gcval(gcid)
long gcid;
{
XprofGCvalues *gcptr;
gcptr = gclist_head;
while( (gcptr != NULL ) && (gcptr->id != gcid) )
gcptr = gcptr->next;
if (gcptr == NULL) /* Cannot find this gcval !! */
fprintf(stderr, "Line %d: Cannot find GC number %lx\n", _LINE_NUM,gcid);
return(gcptr);
}
free_gcval(gcid)
long gcid;
{
XprofGCvalues *previous, *current;
current = gclist_head;
/* Search for this GC */
while((current !=NULL) && (current->id != gcid)) {
previous = current;
current = current->next;
if (current == NULL) { /* Cannot find this gcval !! */
fprintf(stderr, "Line %d: Cannot find GC number %lx\n",
_LINE_NUM,gcid);
return;
}
}
if (current == gclist_head) /* Only one entry in this list !! */
gclist_head = NULL; /* Empty the list */
else previous->next = current->next;/* Remove this from the list */
free(current);
}
copy_gcval(src_id, dst_id, gcmask)
long src_id, dst_id;
int gcmask;
{
XprofGCvalues *src_gcval, *dst_gcval;
src_gcval = get_gcval(src_id);
dst_gcval = get_gcval(dst_id);
if ((src_gcval == NULL) || (dst_gcval == NULL))
return;
/*
* Now modify the appropriate values
*/
if (gcmask & GCFunction)
dst_gcval->function = src_gcval->function;
if (gcmask & GCLineWidth)
dst_gcval->line_width = src_gcval->line_width;
if (gcmask & GCLineStyle)
dst_gcval->line_style = src_gcval->line_style;
if (gcmask & GCFillStyle)
dst_gcval->fill_style = src_gcval->fill_style;
}
fill_gcmask(ptr, gcmask)
char *ptr;
int *gcmask;
{
while ( isspace(*ptr)) ptr++; /* Eat leading white space */
while (!isspace(*ptr)) ptr++; /* Eat the token */
while ( isspace(*ptr)) ptr++; /* Eat leading white space */
if (t_search(ptr, "<ALL>") != 0)
*gcmask = ~0;
else if (t_search(ptr, "0") !=0) {
*gcmask = 0;
}
else while (*ptr) {
if (t_search(ptr, "function") != 0)
*gcmask |= GCFunction;
else if (t_search(ptr, "line-width") != 0)
*gcmask |= GCLineWidth;
else if (t_search(ptr, "line-style") != 0)
*gcmask |= GCLineStyle;
else if (t_search(ptr, "fill-style") != 0)
*gcmask |= GCFillStyle;
else if (t_search(ptr, "font") != 0)
*gcmask |= GCFont;
while (!isspace(*ptr)) ptr++; /* Eat the token */
while ( isspace(*ptr) || (*ptr == '|') ) /* Next gc value */
ptr++;
}
}
fill_gcval(fp, valmask, gcval)
FILE *fp;
int valmask;
XprofGCvalues *gcval;
{
char *ptr;
char sbuf1[132], sbuf2[132]; /* Temp. slots for sscanf*/
char in_string[MAXSTRINGSIZE];
while(valmask) {
if (fgets(in_string,MAXSTRINGSIZE,fp) == NULL) {
return;
}
_LINE_NUM++;
ptr = in_string;
while (isspace(*ptr)) ptr++; /* Remove leading white space */
/* Entry for function ? */
if (t_search(ptr, "function:") != 0) {
valmask &= ~GCFunction; /* function has been found */
sscanf(ptr, "%s %s", sbuf1, sbuf2);
/* Which graphics function is it ? */
if (t_search(sbuf2, "Clear") != 0)
gcval->function = GXclear;
else if (t_search(sbuf2, "And") != 0)
gcval->function = GXand;
else if (t_search(sbuf2, "AndReverse") != 0)
gcval->function = GXandReverse;
else if (t_search(sbuf2, "Copy") != 0)
gcval->function = GXcopy;
else if (t_search(sbuf2, "AndInverted") != 0)
gcval->function = GXandInverted;
else if (t_search(sbuf2, "Noop") != 0)
gcval->function = GXnoop;
else if (t_search(sbuf2, "Xor") != 0)
gcval->function = GXxor;
else if (t_search(sbuf2, "Or") != 0)
gcval->function = GXor;
else if (t_search(sbuf2, "Nor") != 0)
gcval->function = GXnor;
else if (t_search(sbuf2, "Equiv") != 0)
gcval->function = GXequiv;
else if (t_search(sbuf2, "Invert") != 0)
gcval->function = GXinvert;
else if (t_search(sbuf2, "OrReverse") != 0)
gcval->function = GXorReverse;
else if (t_search(sbuf2, "CopyInverted") != 0)
gcval->function = GXcopyInverted;
else if (t_search(sbuf2, "OrInverted") != 0)
gcval->function = GXorInverted;
else if (t_search(sbuf2, "Nand") != 0)
gcval->function = GXnand;
else if (t_search(sbuf2, "Set") != 0)
gcval->function = GXset;
}
/* Entry for line width ? */
else if (t_search(ptr, "line-width:") != 0) {
valmask &= ~GCLineWidth; /* linewidth has been found */
sscanf(ptr, "%s %d", sbuf1, &(gcval->line_width));
}
/* Entry for line style ? */
else if (t_search(ptr, "line-style:") != 0) {
valmask &= ~GCLineStyle; /* linestyle has been found */
sscanf(ptr, "%s %s", sbuf1, sbuf2);
/* Which line style is it ? */
if (t_search(sbuf2, "Solid") != 0)
gcval->line_style = LineSolid;
else if (t_search(sbuf2, "OnOffDash") != 0)
gcval->line_style = LineOnOffDash;
else if (t_search(sbuf2, "DoubleDash") != 0)
gcval->line_style = LineDoubleDash;
}
/* Entry for fill style ? */
else if (t_search(ptr, "fill-style:") != 0) {
valmask &= ~GCFillStyle; /* fillstyle has been found */
sscanf(ptr, "%s %s", sbuf1, sbuf2);
/* Which fill style is it ? */
if (t_search(sbuf2, "Solid") != 0)
gcval->fill_style = FillSolid;
else if (t_search(sbuf2, "Tiled") != 0)
gcval->fill_style = FillTiled;
else if (t_search(sbuf2, "Stippled") != 0)
gcval->fill_style = FillStippled;
else if (t_search(sbuf2, "OpaqueStippled") != 0)
gcval->fill_style = FillOpaqueStippled;
}
else if (t_search(ptr, "font:") != 0) {
long fontid;
valmask &= ~GCFont; /* font has been found */
sscanf(ptr, "%s %s %lx", sbuf1, sbuf2, &fontid);
gcval->fontval = get_fontval(fontid);
}
}
}
gc_gfxindex(fp, req_num, gcval)
FILE *fp;
int req_num;
XprofGCvalues *gcval;
{
int gxmode=0,linestyle=0, fillstyle=0, linewidth=0;/* Respective indices */
int index;
char *req_name;
req_name = RequestType[req_num].name;
/*
* Fill gxmode
*/
index = GxmodeTable[gcval->function].where; /* Where is it ? */
gxmode = GxmodeTable[index].value;
if (gxmode == -1) {
fprintf(fp,
"Line %d -- Error: GxmodeTable has been incorrectly initialized\n",
_LINE_NUM);
exit(1);
}
else if (gxmode != GxmodeTable[gcval->function].value)
fprintf(fp,
"Line %d -- ( %s ) Warning: Can't find gxmode %-12s substituting %s\n",
_LINE_NUM, req_name,
GxmodeTable[gcval->function].xprof_name,
GxmodeTable[index].xprof_name);
/*
* Fill linestyle
*/
index = LineStyleTable[gcval->line_style].where; /* Where is it ? */
linestyle = LineStyleTable[index].value;
if (linestyle == -1) {
fprintf(fp,
"Line %d -- Error: LineStyleTable has been incorrectly initialized\n",
_LINE_NUM);
exit(1);
}
else if (linestyle != LineStyleTable[gcval->line_style].value)
fprintf(fp,
"Line %d -- ( %s ) Warning: Can't find linestyle %-12s substituting %s\n",
_LINE_NUM, req_name,
LineStyleTable[gcval->line_style].xprof_name,
LineStyleTable[index].xprof_name);
/*
* Fill fillstyle
*/
index = FillStyleTable[gcval->fill_style].where; /* Where is it ? */
fillstyle = FillStyleTable[index].value;
if (fillstyle == -1) {
fprintf(fp,
"Line %d -- Error: FillStyleTable has been incorrectly initialized\n",
_LINE_NUM);
exit(1);
}
else if (fillstyle != FillStyleTable[gcval->fill_style].value)
fprintf(fp,
"Line %d -- ( %s ) Warning: Can't find fillstyle %-12s substituting %s\n",
_LINE_NUM, req_name,
FillStyleTable[gcval->fill_style].xprof_name,
FillStyleTable[index].xprof_name);
/*
* Fill linewidth
*/
/* Fetch the index from database created by parse.c */
linewidth = get_db_linewidth_index(gcval->line_width, NOINSTALL);
if (linewidth == -1) {
int tmp;
tmp = get_db_closest_lw(gcval->line_width);
fprintf(fp,
"Line %d -- ( %s ) Warning: Can't find linewidth %2d, substituting %2d\n",
_LINE_NUM, req_name, gcval->line_width, tmp);
linewidth = get_db_linewidth_index(tmp, NOINSTALL);
}
index = GFXINDEX(gxmode, linestyle, fillstyle, linewidth) ;
return (index);
}
/* FontVal maintenance routines */
static FontVal *fontval_list_head = NULL;
FontVal *create_fontval(fontid)
long fontid;
{
FontVal *fontval, *fvptr;
/* Allocate a fontval with all elements zero */
fontval = (FontVal *) calloc(1, sizeof(FontVal));
if (fontval_list_head == NULL) /* Empty list ? Insert at the head */
fontval_list_head = fontval;
else { /* Attach it at the end of the list */
fvptr = fontval_list_head;
while(fvptr->next != NULL)
fvptr = fvptr->next;
fvptr->next = fontval;
fontval->next = NULL;
}
fontval->id = fontid;
return fontval;
}
FontVal *get_fontval(fontid)
long fontid;
{
FontVal *fvptr;
fvptr = fontval_list_head;
while( (fvptr != NULL) && (fvptr->id != fontid) )
fvptr = fvptr->next;
if (fvptr == NULL) /* Cannot find this fontval !! */
fprintf(stderr, "Line %d: Cannot find Font number %lx\n", _LINE_NUM,fontid);
return(fvptr);
}
free_fontval(fontid)
long fontid;
{
FontVal *previous, *current;
current = fontval_list_head;
/* Search for this Font */
while( (current != NULL) && (current->id != fontid) ) {
previous = current;
current = current->next;
if (current == NULL) { /* Cannot find this fontval !! */
fprintf(stderr, "Line %d: Cannot find Font number %lx\n",
_LINE_NUM,fontid);
return;
}
}
if (current == fontval_list_head) /* Only one entry in this list !! */
fontval_list_head = NULL; /* Empty the list */
else previous->next = current->next;/* Remove this from the list */
if (current->fontname !=NULL)
free(current->fontname);
free(current);
}
gc_fontindex(fp, req_num, gcval)
FILE *fp;
int req_num;
XprofGCvalues *gcval;
{
int index=0;
index=get_db_fontname_index(gcval->fontval->fontname, NOINSTALL);
if (index == -1) {
index = 0;
fprintf(fp,
"Line %d -- ( %s ) Warning: Can't find font %s substituting %s\n",
_LINE_NUM, RequestType[req_num].name,
gcval->fontval->fontname, db_font_name(index));
}
return(index);
}